
function WebEntityComboList(id, type)
{
    this.superClase = WebComboList;
    this.superClase(id, type);
          
    this.entityName = "";
    this.orderBy = "";
    this.foreingProperty = "";    
    this.initValue = "";      

    this.loadingString = "Loading...";
    
	this.Clone = EntityComboList_Clone;
	
	this.Fill  = EntityComboList_Fill;
	this.BeginLoading = EntityComboList_BeginLoading;
	this.EndLoading = EntityComboList_EndLoading;
	this.evalOnChange = EntityComboList_EvalOnChange;
	this.RefreshData = EntityComboList_RefreshData;
	this.RefreshDataSinc = EntityComboList_RefreshDataSinc;
}

function EntityComboList_Clone(newId)
{
    var newCombo = new WebEntityComboList(newId, this.type);

	newCombo.width = this.width;
	newCombo.size = this.size;
	newCombo.labelclear = this.labelclear;
	newCombo.multiselect = this.multiselect;
	newCombo.redraw = this.redraw;
    newCombo.cssClass = this.cssClass;
    
	newCombo.items = this.items.slice();
	newCombo.count = this.count;
	newCombo.resizable = this.resizable;
	newCombo.scroll = this.scroll;
	newCombo.enabled = this.enabled;
	
    newCombo.entityName = this.entityName;
    newCombo.orderBy = this.orderBy;
    newCombo.foreingProperty = this.foreingProperty;
    		
	return newCombo;
}

function EntityComboList_EvalOnChange()
{
    if(typeof(Relationship_EvalOnChange) != "undefined")
        Relationship_EvalOnChange(this.id, this.GetValueList());	
        
    eval(this.onChange);
}

function EntityComboList_Fill(items)
{
    if(!Common.isArray(items))    
        return -1;
        
    this.redraw = false;  
    this.ClearList();

    var keyvalue;
    for(var i=0; i<items.length; i++)
    {
        keyvalue = items[i].split("|");
        this.AddItem(keyvalue[0], keyvalue[1]);
    }
    
    this.redraw = true;  
    this.Refresh();
}

function EntityComboList_BeginLoading()
{
    this.Disable();

	var combo = document.getElementById("selec" + this.id);
	
	if(this.type==2)
        combo.innerHTML = "&nbsp;" + this.loadingString;
	else if(this.type==3)
        combo.value = this.loadingString;
}

function EntityComboList_EndLoading()
{
    this.Enable();

	var combo = document.getElementById("selec" + this.id);
	
	if(this.type==2)
        combo.innerHTML = "&nbsp;";
	else if(this.type==3)
        combo.value = "";
}

function EntityComboList_RefreshData(parentValue)
{
    var property = this.foreingProperty;
    var orderBy = this.orderBy;
    
    if(!parentValue)  
        parentValue = "";
        
    // llamado Ajax para refrescar la lista 
    this.BeginLoading();      	
    EntityComboList.GetList(this.entityName, property, parentValue, orderBy, EntityComboList_GetListCallBack, this.id);
}

function EntityComboList_RefreshDataSinc(parentValue)
{
    var property = this.foreingProperty;
    var orderBy = this.orderBy;
    
    if(!parentValue)
        parentValue = "";
        
    // llamado Ajax para refrescar la lista 
    this.BeginLoading();      	
    
    var response = EntityComboList.GetList(this.entityName, property, parentValue, orderBy);
    response.context = this.id;
    EntityComboList_GetListCallBack(response);
}

function EntityComboList_RegisterRelationship(idparent, idchild)
{
    Entity_Relationships[idparent] = idchild;
}

function EntityComboList_GetListCallBack(response)
{
    var listId = response.context;
    var mlist = ComboList_Instances[listId];

    if ( (response.error) && (typeof(response.error) != "xml") ) {
        alert(response.error);
    }
    else {
        var items = response.value;
        if (items) 
            mlist.Fill(items);
            
        mlist.evalOnChange();          
    }    

    mlist.EndLoading();    
}    
